#include <regx52.h>
#include "timer.c"
/**
 * 实现一个按键，每次点击按键点亮8个灯中随机数量，随机位置的灯
 * 保证至少有一个灯被点亮
 */
void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

sbit BTN = P1 ^ 0;

#define LEDS P2

/**
 * 当没有按键按下，返回0xFF
 * 按下返回0
 */
unsigned char btn_scan()
{
    if (BTN == 0)
    {
        delay_ms(20);
        if (BTN == 0)
        {
            while (BTN == 0)
                ;
            return 0;
        }
    }
    return 0xFF;
}

void main()
{
    timer0_init();
    while (1)
    {
        // if (btn_scan() != 0xFF)
        // {
        //     timer_seed = get_timer0_value();
        //     LEDS = timer_rand() % 0xFF;
        // }

        timer_seed = get_timer0_value();
        LEDS = timer_rand() % 0xFF;
        delay_ms(500);
    }
}
